//
//  UIImage+Extension.swift
//  SinaWB_XY
//
//  Created by 小熊猫 on 15/10/22.
//  Copyright © 2015年 小熊猫. All rights reserved.
//

import Foundation
import UIKit

extension UIImage{
    //把图片缩放的方法
    func Scale(scaleWidth:CGFloat) -> UIImage{
        
        if self.size.width <= scaleWidth{
            return self
        }
        
        let scaleHeight = scaleWidth / size.width * size.height
        
        let scaleSize = CGSizeMake(scaleWidth, scaleHeight)
        
        //开启图形上下文
        UIGraphicsBeginImageContext(scaleSize)
        
        drawInRect(CGRect(origin: CGPointZero, size: scaleSize))
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        
        //关闭图形上下文
        UIGraphicsEndImageContext()
        
        return result
    }
}